<?php
/*
 * 
 * implementare subcapitol
 * 
 */
//require_once ('xmlChapter.class.php');

class xmlSubChapter{
	private $dom;
	private $parentNode;
	private $parentPath;
	private $subRoot;
	private $subChapterElements=array();

	/**
	 * constructor
	 * @access public
	 * @param DOMElement $parent parintele subcapitolului
	 * @param DOMDocument $dom handlerul documentului
	 * @param string $id id-ul noului subcapitol
	 * @param string $title continutul elem title
	 * @return bool TRUE if no error occurs
	 */
	public function __construct(& $parent, & $dom, $parentPath, $id, $title) {
		$this->parentNode = & $parent;
		$this->dom = & $dom;
		$this->parentPath=$parentPath;
		
		$newSub = $this->dom->createElement('subChapter');
		$newSubId = new DOMAttr('subChapId', $id);
		$newSub->appendChild($newSubId);
		$newSubTitle=$this->dom->createElement('title',$title);
		$newSub->appendChild($newSubTitle);
		
		$this->parentNode->appendChild($newSub);
		$this->subRoot=& $newSub;
		return true;
	}
	
	public function createNewParagraph($id, $text) {
		//tretare erori!!! try
		$newParagr = new xmlBasicElements(& $this->subRoot, & $this->dom);
		$newParagr->createParagraph($id, $text);
		$this->dom->save($this->parentPath);
	}
	
	public function createNewSection($id, $title){
		$newSection=new xmlSection(& $this->subRoot, & $this->dom, $this->parentPath, $id, $title);
		try{
			$this->dom->save($this->parentPath);
			$this->subChapterElements[$id]=& $newSection;
			return $this->subChapterElements[$id];
		}catch(exception $e){
			echo $e->getmessage();
			return false;
		}
	}
}
?>